import java.util.ArrayDeque;
import java.util.Deque;

/**
 * 155. 最小栈
 */
public class Solution_155 {
    public static void main(String[] args) {
        MinStack minStack = new MinStack();
        minStack.push(-2);
        minStack.push(0);
        minStack.push(-3);
        int min = minStack.getMin();
        System.out.println("min : " + min);
        minStack.pop();
        int top = minStack.top();
        System.out.println("top : " + top);
        minStack.getMin();
        min = minStack.getMin();
        System.out.println("min : " + min);
    }
}

/**
 * 剑指 Offer 30.
 */
class MinStack {
    private Deque<Integer> dataStack;
    private Deque<Integer> minStack;

    /** initialize your data structure here. */
    public MinStack() {
        this.dataStack = new ArrayDeque<Integer>();
        this.minStack = new ArrayDeque<Integer>();
    }

    public void push(int val) {
        dataStack.push(val);
        if (minStack.isEmpty() || val < minStack.peek()) {
            minStack.push(val);
        } else {
            minStack.push(minStack.peek());
        }
    }

    public void pop() {
        dataStack.pop();
        minStack.pop();
    }

    public int top() {
        return dataStack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}

/**
 * Your MinStack object will be instantiated and called as such: MinStack obj =
 * new MinStack(); obj.push(val); obj.pop(); int param_3 = obj.top(); int
 * param_4 = obj.getMin();
 */